using UnityEngine;

public class RefereeStateFreeThrow : State<Referee>
{
	private static RefereeStateFreeThrow instance;

	private RefereeStateFreeThrow()
	{
	}

	public static RefereeStateFreeThrow getInstance()
	{
		if (instance == null)
		{
			instance = new RefereeStateFreeThrow();
		}
		return instance;
	}

	public override void fixedUpdate(Referee owner)
	{
		base.fixedUpdate(owner);
		if (Instance<Court>.instance.count_FreeThrow == 0)
		{
			owner.do_playing();
		}
		else if (Instance<Ball>.instance.isInState(BallState_Rebound.getInstance()) || Instance<Ball>.instance.isInState(BallState_Idle.getInstance()))
		{
			if (Instance<Ball>.instance.isGetBall(owner.getPosition()))
			{
				Instance<Ball>.instance.getBallInHand(owner.trans_ball);
				owner.playAnimation(AnimationName.player_dribble_run, 1f, -1f);
				Instance<Ball>.instance.do_dribble_run();
			}
			else
			{
				GameHelper.MoveTo(owner, MathHelper.setY(Instance<Ball>.instance.getPosition(), 0f), Global.MaxMoveSpeed_Referee, isLookAtTargetPos: true);
				owner.playAnimation(AnimationName.referee_run, 1f, -1f);
			}
		}
		else if (Instance<Ball>.instance.isInState(BallState_Dribble_Run.getInstance()))
		{
			Vector3 position = Instance<Ball>.instance.getPosition();
			if (GameHelper.MoveTo(owner, (!(position.z > 0f)) ? Global.pos_FreeThrow_Right_Referee : Global.pos_FreeThrow_Left_Referee, Global.MaxMoveSpeed_Referee, isLookAtTargetPos: true))
			{
				owner.LookAt(Vector3.zero);
				owner.GetComponent<Animation>().Play("pass_d1");
				Instance<Ball>.instance.pass_player_catch_ball = Instance<Ball>.instance.shoot_player;
				Instance<Ball>.instance.getBallInHand(owner.trans_ball);
				Instance<Ball>.instance.do_pass(_isRerferPass: true);
			}
		}
		else if (Instance<Ball>.instance.isInState(BallState_Dribble_Stay.getInstance()) && Instance<Ball>.instance.shoot_player.teamType == TeamType.COMPUTER && !owner.IsInvoking("freethrow"))
		{
			Instance<Ball>.instance.shoot_player.do_dribble_stay();
			owner.Invoke("freethrow", Random.Range(2, 4));
		}
	}

	public override void exit(Referee owner)
	{
		base.exit(owner);
		Instance<Ball>.instance.isOutSide = false;
	}
}
